<?php
define('APPTYPEID', 4);
define('CURSCRIPT', 'portal');

require './source/class/class_core.php';


function discuz_clear($str)
{
	$discuz = & discuz_core::instance();
	$discuz->init();
	
	$ret = DB::fetch_all('SELECT tid, message FROM ' . DB::table('forum_post'));
//var_dump($ret);
	foreach($ret as $result)
	{
		if(($pos = stripos($result['message'], $str)) !== false)
		{
			$content = substr($result['message'], $pos + strlen($str));
			$content = trim($content);
			$tid = $result['tid'];
			DB::update('forum_post', array('message'=>$content), "tid='{$tid}'");
		}
	}
}

function discuz_clear_2($str, $rep)
{
	$discuz = & discuz_core::instance();
	$discuz->init();
	
	$ret = DB::fetch_all('SELECT tid, message FROM ' . DB::table('forum_post'));
//var_dump($ret);
	foreach($ret as $result)
	{
			$content = str_replace($str, $rep, $result['message']);
			
			if(strlen($content) + 100 > strlen($result['message']))
			{
				$tid = $result['tid'];
				DB::update('forum_post', array('message'=>$content), "tid='{$tid}'");
			}
	}
}

function discuz_clear_3($str, $rep, $is_reg=false, $reg='//')
{
	$discuz = & discuz_core::instance();
	$discuz->init();
	
	$ret = DB::fetch_all('SELECT tid, message FROM ' . DB::table('forum_post'));

	foreach($ret as $result)
	{
		if(($pos = stripos($result['message'], $str)) !== false)
		{
			if($is_reg)
			{
				$content = preg_replace($reg, $rep, $result['message']);
			}
			else
			{
				$content = str_replace($str, $rep, $result['message']);
			}
			//var_dump($content);
			if(strlen($content) + 100 > strlen($result['message']))
			{
				$tid = $result['tid'];
				DB::update('forum_post', array('message'=>$content), "tid='{$tid}'");

				echo $tid . "<br>";
			}
		}
	}
}


//discuz_clear_2(array('\"', '&nbsp;', '&ldquo', '&rdquo'), array('"', ' ', '”', '“'));


//discuz_clear('rightshow();');


//discuz_clear_3('<a href=\"http', "", true, '/<a href=\\"http./ig');

discuz_clear_3('&hellip;', '...');
discuz_clear_3('&quot;', '"');

?>